package com.zhj.pay;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;

import java.lang.reflect.Constructor;

import pay.zhj.com.paystand.PayInterface;

public class ProxyActivity extends Activity {
    private String className;
    private PayInterface payInterface;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        className = getIntent().getStringExtra("className");

        try {
            Class activityClass = getClassLoader().loadClass(className);
            Constructor constructor = activityClass.getConstructor(new Class[]{});
            Object instance = constructor.newInstance(new Object[]{});

            //标准
            payInterface = (PayInterface) instance;
            payInterface.attach(this);

            //传递参数
            Bundle bundle = new Bundle();
            payInterface.onCreate(bundle);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void onStart() {
        super.onStart();
        payInterface.onStart();
    }

    @Override
    protected void onPause() {
        super.onPause();
        payInterface.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        payInterface.onDestroy();
    }

    @Override
    public ClassLoader getClassLoader() {
        return PluginManager.getsInstance().getDexClassLoader();
    }


    @Override
    public Resources getResources() {
        return PluginManager.getsInstance().getResources();
    }




}
